import { request } from "@/utils/request";

/**
 * 根据文章id查询所有评论
 * @param id
 * @returns
 */
export const byessay = (id: string) => {
  return request.get(`/comment/byessay/${id}`);
};

/**
 * 回复评论
 * @param content : 评论内容;
 * @param userid : 用户id
 * @param commentid : 回复评论的id
 * @param essayid : 文章id
 * @returns
 */
export const replyapi = (
  content: string,
  userid: number,
  commentid: number,
  essayid: number
) => {
  return request.post("/comment/reply", {
    content,
    userid,
    commentid,
    essayid,
  });
};

/**
 * 删除评论
 * @param id 评论id
 * @returns
 */
export const deletecommentapi = (id: number) => {
  return request.delete(`/comment/deletecom/${id}`);
};

/**
 * 点赞或取消点赞评论
 * @param type 取消点赞还是点赞
 * @param userid 用户id
 * @param commentid 评论id
 * @returns
 */
export const thumbcommentapi = (
  type: number,
  userid: number,
  commentid: number
) => {
  return request.post("/comment/thumb", { type, userid, commentid });
};

/**
 * 获取用户的所有评论
 * @param user_id 用户id
 * @returns
 */
export const byuserapi = (user_id: number) => {
  return request.get(`/comment/byuser/${user_id}`);
};

/**
 * 删除评论
 * @param id
 * @returns
 */
export const deletecomapi = (id: number) => {
  return request.delete(`/comment/deletecom/${id}`);
};
